<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ include file="/common/taglibs.jsp" %>
<html>
<head>
  <%@ include file="/common/meta.jsp" %>
  <title>流程实体</title>
  <link href="<c:url value='/views/flow/css/flow_common.css'/>" rel="stylesheet" type="text/css"/>
  <style type="text/css">
    .bodytable0 td div{float: left;}
  </style>
  <script type="text/javascript">
    var _path = "${_ctx}/flow/processEntity";
    var _app_path = "${_ctx}/bap/application";
    $(function () {
      toolbar();
      $("#appName").ligerComboBox({
                url: _app_path + '/getComboBoxData',
                valueField: 'id',
                textField: 'name',
                valueFieldID: 'appId',
                selectBoxWidth: 180,
                selectBoxHeight: 240,
                width: 180,
                cancelable: false,
                renderItem: function (e) {
                  var data = e.data;
                  var out = [];
                  out.push('<div>' + data.name + '</div>');
                  return out.join('');
                }
              }
      );
      $("#appId").val("${processEntity.appModule.id}");
      $("#appName").val("${processEntity.appModule.name}");
      $("#mainForm").ligerForm({validate: true});
    });

    function toolbar() {
      var items = [];
      items.push({type: 'button', text: "保存", icon: 'save', click: function () {
        f_save();
      }});
      items.push({type: 'button', text: "取消", icon: 'delete', click: function () {
        f_cancel();
      }});
      items.push({type: 'button', text: "返回", icon: 'view', click: function () {
        f_back();
      }});

      $("#toolbar").ligerToolBar({items: items });
    }

    //保存
    function f_save() {
      var formObj = $("#mainForm");
      if (formObj.valid()) {
        var saveData = formObj.serializeJson();

        $.ligerDialog.openWaitting('数据保存中,请稍候...');
        $.ajax({
          url: _path + "/save", type: "POST",
          contentType: 'application/json;charset=utf-8', //设置请求头信息
          dataType: "json",
          data: JSON2.stringify(saveData),
          success: function (result) {
            BAP.closeWaitting();
            if (!result['isError']) {
            	$.ligerDialog.showSuccess("成功");
              document.location.href = _path + '/edit?id=' + result['data'];
            } else {
            	$.ligerDialog.showError(result.msg);
            }
          },
          error: function () {
        	  $.ligerDialog.closeWaitting();
        	  $.ligerDialog.showError('操作失败！');
          }
        });
      }
    }

    //取消
    function f_cancel() {
      var tabId = BAP.getCurrentTabId();
      BAP.reloadTab(tabId);
    }

    //返回
    function f_back() {
      BAP.overrideSelectedTabItem(_path + '/list', '流程实体');
    }

  </script>
</head>
<body style="margin: 0;">
<%-- 工具栏 --%>
<div id="toolbar"></div>
<%-- 表单 --%>
<div>
  <form:form modelAttribute="processEntity" id="mainForm" method="post" onsubmit="return false">
    <form:hidden path="id" id="id" ltype="text"/>
    <form:hidden path="appId" id="appId" ltype="text"/>
    <table style="width: 600px; margin: 5px;" class='bodytable0'>
      <tr>
        <td width="62px">
          <div align="right" style="width: 100px">应用：</div>
        </td>
        <td colspan="3">
          <input type="text" id="appName" name="appName" validate="{required:true}"/>
          <span class="req_star">*</span>
        </td>
      </tr>
      <tr>
        <td width="62px">
          <div align="right" style="width: 100px">编码：</div>
        </td>
        <td colspan="3">
          <form:input id="code" path="code" ltype="text" ligerui="{width:180}" validate="{required:true}"/>
          <span class="req_star">*</span>
        </td>
      </tr>
      <tr>
        <td width="62px">
          <div align="right" style="width: 100px">实体名称：</div>
        </td>
        <td colspan="3">
          <form:input id="entityName" path="entityName" ltype="text" ligerui="{width:180}" validate="{required:true}"/>
          <span class="req_star">*</span>
        </td>
      </tr>
    </table>
  </form:form>
</div>
</body>
</html>
